package com.obixlabs.smorgasbord.domainmodel;

import java.io.Serializable;
import java.util.Arrays;

import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang.builder.HashCodeBuilder;

@XmlType
public class SimpleIdentifier implements Serializable
{
	private static final long serialVersionUID = -8423044686924841905L;

	private Object[] constituents;
	
	public SimpleIdentifier(Object ... constituents)
	{ this.constituents = constituents;}
	
	protected Object[] getConstituents() { return constituents; }
	
	@Override
	public boolean equals(Object obj)
	{
		boolean result;
		
		if (this == obj)
			result = false;
		else if (getClass().isInstance(obj))
		{
			SimpleIdentifier other = (SimpleIdentifier) obj;
			result = Arrays.equals(this.constituents, other.constituents);
		}
		else result = false;
		
		return result;
	}
	
	@Override
	public int hashCode()
	{
		HashCodeBuilder result = new HashCodeBuilder();
		
		for (Object constituent : this.constituents)
			result.append(constituent);

		return result.toHashCode();	
	}//end method def
}//END CLASS DEF